package com.example.springboot.service.impl;

import com.example.springboot.mapper.UserMapper;
import com.example.springboot.service.UserService;
import entity.CityChild;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    //@Autowired
    //private SqlSession sqlsession;

    @Autowired
    private SqlSessionFactory sqlSessionFactory;

    @Override
    public void test2() {
        userMapper.insert1();

        int a=userMapper.count3();
        System.out.println("=============="+a);
        //开始测试获取sqlsession
        // 获取sqlSession
      // SqlSession session = sqlSessionFactory.openSession();
      // session.select("com.mybatis.mapper.RoleMapper.getRole",1L);

       System.out.println("++++++++++++++=");
    }

    @Override
    @Transactional(isolation=Isolation.READ_UNCOMMITTED)
    public void test3() {
       String  n1= userMapper.count1();//select name
        System.out.println(n1);
    }


    @Override
    @Transactional(isolation=Isolation.REPEATABLE_READ)
    public String test(int num) {
        System.out.println("=============");
        String n1= userMapper.count1();//select name
        Integer b2= userMapper.count2();//select count (*)
        System.out.println(b2);
        //userMapper.insert1();
        b2= userMapper.count2();//select count (*)

        //userMapper.update3();
     //  n1= userMapper.count1();//select name
       // String  n2=userMapper.count1();
        System.out.println(b2);
        test3();
        return "OK";
    }

    @Override
    @Transactional(isolation=Isolation.REPEATABLE_READ)
    public CityChild test4() {
        return userMapper.getAllCity();
    }
}
